package com.base.simple.main.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.IntentCompat;
import android.view.View;
import android.widget.Button;

import com.base.simple.Constants;
import com.base.simple.R;
import com.base.simple.main.MainActivity;
import com.base.simple.main.event.ChangeStyleEvent;
import com.dream.base.eventbus.EventBusManager;
import com.dream.base.tools.SharedPreferencesUtil;
import com.dream.base.ui.BaseFragment;

/**
 * @Description: 测试用的fragment
 * @author: Wang
 * @date: 2018/1/5 9:53
 * @email: life_artist@163.com
 * @Copyright©2018 by wang. All rights reserved.
 */

public class SimpleFragment extends BaseFragment {

    private Button changeButton;

    private int count = 0;

    @Override
    protected int setViewLayout() {
        return R.layout.fragment_simple;
    }

    @Override
    protected void findViews(View view) {
        changeButton = (Button) view.findViewById(R.id.change_button);
    }

    @Override
    protected void initViews() {
        changeButton.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("WrongConstant")
            @Override
            public void onClick(View v) {
                count++;
                if (count % 2 == 0) {
                    SharedPreferencesUtil.setInt(getContext(), Constants.CURRENT_STYLE, R.style.PrimaryStyle);
                    EventBusManager.getInstance().post(new ChangeStyleEvent(R.color.colorPrimary));
                } else {
                    SharedPreferencesUtil.setInt(getContext(), Constants.CURRENT_STYLE, R.style.LightGreenStyle);
                    EventBusManager.getInstance().post(new ChangeStyleEvent(android.R.color.holo_green_light));
                }
            }
        });
    }
}
